package testEnum;

/**
 * @author 徐志荣
 * @date 2023/2/21 17:44
 */
public enum TestEnum {
    RED(1,"red"),BLACK(2,"black"),GREEN(3,"green");

    public String color;
    public int ordinal;
    private TestEnum(int ordinal,String color){
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i]+"索引: "+testEnums[i].ordinal());
        }
        System.out.println("***************");
        TestEnum testEnum = TestEnum.valueOf("GREEN");
        System.out.println(testEnum);

        System.out.println(RED.compareTo(GREEN));
    }

    public static void main1(String[] args) {
        TestEnum color = RED;
        //使用场景1:枚举可以作为 switch的参数
        switch (color){
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;

        }
    }

}
